Jason Freels
04 January 2018
Getting started with Git and Github
The basics of version control systems
Using Git and Github for collaborative software development
A decentralized version control system that's free and open source
An excellent way to track and coordinate file changes among many people
A filing system for every draft of a document
A tool invented by Linus Torvalds (and the Linux development community) to develop the Linux kernel in 2005
The most widely used modern version control system in the world --
Free software distributed under the terms of the GNU General Public License version 2
While mainly used for code, Git can be used to manage any type of file/project
Word documents
Final Cut projects
The entire volume of German federal laws
A code sharing and publishing service
A social networking site for programmers
The single largest web-based service for hosting Git repositories
A popular way to collaborate on code (no more emails and zip files!!)
The development versions of many R packages are hosted on GitHub: https://github.com/tidyverse/ggplot2
All the cool kids are using it!
Includes several features beyond command-line Git
A Web-based graphical interface
Task/project management tools
A martketplace of integrations for many 3rd party services
Issues!
Forking!
Workflows without Git typically consist of
Before getting too deep into Git, let's take a step back
Git is one of many different version control systems (VCS)
It's important to understand what a VCS is and the different types of VCS that exist
New users often struggle with understanding how to use Git
This misunderstanding is driven by the fact that there seems to be an endless number of use cases
There several Methods for using Git
Super secret hybrid method
At the command line
Within an IDE (e.g. RStudio)
From a Git desktop GUI
For Mac, Linux, and Unix users
For Windows users
After Git has installed
$ git config --global user.name "Brandon Greenwell" $ git config --global user.email greenwell.brandon@gmail.com
--global, you only need to do this once!cd (change directories)git init (initialize a folder as a Git repo)git add <file-name> (start tracking a new file)git commit -m "fix typo" (commit your changes)git clone (clone/copy another Git repo [e.g., from GitHub])git push origin master (push your master branch to your origin server)git pull origin master (update your local repo) Tip: Typing git add --all will start tracking everything (this is how I almost always use git add).Initialize a repo in an existing directory
arithmetic anywhere on your computer (e.g., the Desktop)add.Radd <- function(x, y) { x * y }Next, open a terminal or Git Bash (Windows) and go to the project's root directory
For example, the code below takes me to the folder called arithmetic on my Desktop
cd C:/Users/greenweb/Desktop/arithmeticgit initTip: the command line has a history (just like the R console), so you don't need to type as often; just hit the up arrow and make any necessary changes!
If you want to start version controlling all the files, you need to start tracking them. In the terminal, type the following:
then type:
The first thing you need to do is set up an account: https://github.com/
Use the same e-mail address you used when setting up Git!
Refresh your browswer and see if it worked!
Fix the obvious typo in add.R. Then, take a snapshot (i.e., git add/commit) and push the changes to GitHub (i.e., git push)!
Refresh your browser to see the changes.
Tip: It's good practice to do this every time you make a key change (e.g., fix a typo, add a new function to an R script, etc.).
* Make sure you're in the right directory!
Any questions?